home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
redakcyjne
/
programy
/
FEBE (Firefox Environment Backup Extension) 5.0
/
febe-5.0-fx.xpi
/
chrome
/
febe.jar
/
content
/
febeDrag.js
< prev
next >
Wrap
Text File
|
2007-03-02
|
4KB
|
89 lines
// Drag and drop code
// Taken from template at http://kb.mozillazine.org/Dev_:_Extensions_:_Example_Code_:_Adding_Drag_and_Drop_to_Statusbarpanel
var febeStatObserver = {
init: function () {
febeStatObserver.flavour = "febeFla"; //any text you want but should have something to do with the extension name
febeStatObserver.statusbarPanel = "febestatusbar";//id of the statusbarpanel to drag
febeStatObserver.statbar = "status-bar";//name of statusbar
febeStatObserver.prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.febe.statpos.");
if(febeStatObserver.prefs.prefHasUserValue("insertAfter")){
document.getElementById(febeStatObserver.statbar).insertBefore(document.getElementById(febeStatObserver.statusbarPanel),document.getElementById(febeStatObserver.prefs.getCharPref("insertAfter")));
}
},
getSupportedFlavours: function () {
var flavours = new FlavourSet();
flavours.appendFlavour(febeStatObserver.flavour);//text/unicode
return flavours;
},
onDragStart: function (evt,transferData,action){
var elme = evt.target;
while(elme != document.getElementById(febeStatObserver.statusbarPanel)){
elme =elme.parentNode;
}
var txt=elme.getAttribute("id");
transferData.data=new TransferData();
transferData.data.addDataForFlavour(febeStatObserver.flavour,txt);
var status = document.getElementById(febeStatObserver.statusbarPanel);
var statusbar = document.getElementById(febeStatObserver.statbar);
var child = statusbar.firstChild;
var x = 0;
while (child) {
if (child != status) {
if (!child.id) {
var newId = "statusbarpanel-noID"+x;
while (document.getElementById(newId)) newId += "x"+x;
child.id = newId;
child.setAttribute("persist", new String("id" + (child.persist ? " "+child.persist : "")) );
x++;
}
if (child.childNodes.length == 0 && document.getAnonymousNodes(child).length == 0)
child.setAttribute("abnochildren", true);
child.addEventListener("dragenter", function(event) { nsDragAndDrop.dragEnter(event,febeStatObserver); }, false);
child.addEventListener("dragover", function(event) { nsDragAndDrop.dragOver(event,febeStatObserver); }, false);
child.addEventListener("dragdrop", function(event) { nsDragAndDrop.drop(event,febeStatObserver); }, false);
}
child = child.nextSibling;
}
window.addEventListener("dragexit", function(event) { nsDragAndDrop.dragExit(event,febeStatObserver); }, true);
},
onDragEnter: function (evt,flavour,session){
var elm = evt.target;
while(elm.nodeName != "statusbarpanel"){
elm = elm. parentNode;
}
},
onDragOver: function (evt,flavour,session){
var elm = evt.target;
while(elm.parentNode.nodeName != "statusbar"){
elm = elm.parentNode;
}
},
onDrop: function (evt,dropdata,session){
if (dropdata.data!=""){
prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.febe.statpos.");
var elm = evt.target;
while(elm.nodeName != "statusbarpanel"){
elm = elm.parentNode;
}
// 'delta' is the difference between the mouse position when
// the drop event occurs and the middle of the target's boxObject
// delta > 0 if the mouse is on the right of the middle
var delta = evt.clientX - (elm.boxObject.x + elm.boxObject.width / 2);
var elem = document.getElementById(dropdata.data);
var parent = elem.parentNode;
elem.setAttribute("insertafter",""+elm.getAttribute("id"));
(delta > 0) && (elm = elm.nextSibling);
if (elm) {
parent.insertBefore(elem,elm);
}
else {
parent.appendChild(elem);
}
// store the actual position into preferences
prefs.setCharPref("insertAfter",elm.getAttribute("id")+"");
}
}
};
window.addEventListener('load', febeStatObserver.init, false);